package net.sk.china.front.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sk.china.common.response.CommonResult;
import net.sk.china.common.utils.TalkUtil;
import net.sk.china.front.request.PayRequest;
import net.sk.china.front.request.order.OrderPayRequest;
import net.sk.china.front.response.PayResultResponse;
import net.sk.china.front.response.order.OrderPayResultResponse;
import net.sk.china.front.service.PayService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * +----------------------------------------------------------------------
 * | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2018-2024 聊来All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">apache</a> )
 * +----------------------------------------------------------------------
 * | @Author: 聊来 <18970881148@qq.com>
 * +----------------------------------------------------------------------
 * | DateTime: 2024/6/4 17:34
 * +----------------------------------------------------------------------
 */

@RestController
@RequestMapping("pay/")
@Api(tags = "支付管理")
public class PayController {

    private final PayService payService;

    public PayController(PayService payService) {
        this.payService = payService;
    }

    @ApiOperation(value = "支付范例")
    @RequestMapping(value = "demo", method = RequestMethod.POST)
    public CommonResult<PayResultResponse> login(@RequestBody @Validated PayRequest request, HttpServletRequest httpServletRequest) {
        request.setClientIp(TalkUtil.getClientIp(httpServletRequest));

        return CommonResult.success(payService.demo(request));
    }

    @ApiOperation(value = "订单支付")
    @RequestMapping(value = "payment", method = RequestMethod.POST)
    public CommonResult<OrderPayResultResponse> payment(@RequestBody @Validated OrderPayRequest orderPayRequest, HttpServletRequest request) {
        String ip = TalkUtil.getClientIp(request);
        return CommonResult.success(payService.payment(orderPayRequest, ip));
    }
}
